* Author: Anina Schwarzenbach
* generated October 2014
* last review August 2020

clear
use "../../STATAfiles/FR_POLIS_31juillet14_FINAL&IRIS_mb.dta"

*load ADOS
sysdir set PERSONAL "../../../ados"

set more off

*******************************************************************************************
*RECODINGS OF VARIABLES - FRANCE
******************************************************************************************

**** CHECK STATUS
*use dataset with new migration variables & last contact
*dole different from previous versions (handling missings)

******************************** GENERAL ********************************
gen kid= num
label var kid "num. questionnaire"

gen schlid = CodeEtabEnov + 1000
lab var schlid "ID school"

gen country = 1
lab define countrylb 1"France" 0"Germany"
label value country countrylb

gen city = -1
replace city=1 if Site==1
replace city=2 if Site==2
lab var city "city"
lab define citylb 1"Grenoble" 2"Lyon" 3"Cologne" 4 "Mannheim", replace 
label value city citylb

*** type of school
*DE: xtyp

fre NomEtab Site Secteur TypEtab6 TypEtab2 NivClasse TypClasse4 TypClasse2 Filiere5 Filiere3 Filiere2

******************************** INDIVIDUAL DEMOGRAPHICS ********************************
*** sex
recode Q1 (1=0) (2=1), gen(sex)
label var sex "sex"
lab define sexlb 0"boys" 1"girls"
lab val sex sexlb

**** age 
gen age1=age
label var age1 "age continuous"
*replace age1=18 if age>= 19
*label var age1 "age continuous - cut after 18"

gen age2 = round(age)
recode age2 (min/12=12) (18/max=18) (.=99)
lab var age2 "age continuos- recoded"
lab define age2lb 12"up to 12" 18"18+" 99 "missing"
label val age2 age2lb

recode age2 (12/13=13) (17/18=17), gen (age3)
lab define age3lb 13"12-13" 17"17-18" 99 "missing"
label val age3 age3lb

gen age4 = age1
label variable age4 "age categorical"
replace age4 = 13 if age1 <14
replace age4 = 14 if age1 >= 14 & age1 < 15
replace age4 = 15 if age1 >= 15 & age1 < 16
replace age4 = 16 if age1 >= 16 & age1 < 17
replace age4 = 17 if age1 >=17 & age1 < 18
replace age4 = 18 if age1 >= 18

codebook  age1-age4

******** ******** ******** ******** ******** ******** 
** migration SEE MIGRATION DE DOFILE
gen ethnic1 = ethn2FR
label var ethnic1 "ethnicity large 7 categories"
label define ethnic1lb 0 "native" 1 "Europe" 2 "Turkey(D)/Maghreb(F)" 3"Africa and Ex-Soviet(D)/Middle East(F)" 4"Asia and World" 5 "Mixed native and Turkey(D)/Maghreb(F)" 6"Mixed native and other" 99 "Missing", replace
lab val ethnic1 ethnic1lb
tab ethnic1

gen ethnic2= ethnic1
label var ethnic2 "ethnicity short 5 categories"
recode ethnic2 (2=1) (1=2) (3=2) (4=2) (5=3) (6=4) (99=.)
label define ethnic2lb 0 "native" 1 "Turkey(D)/Maghreb(F)" 2 "other MB" 3 "Mixed native and Turkey(D)/Maghreb(F)" 4 "Mixed native and other", replace
label value ethnic2 ethnic2lb
tab ethnic2

gen ethnic3= ethnic2
label var ethnic3 "ethnicity short 3 categories - mixed as native"
recode ethnic3 (3/4=0) 
label define ethnic3lb 0 "native" 1 "Turkey(D)/Maghreb(F)" 2 "other MB" , replace
label value ethnic3 ethnic3lb
tab ethnic3

gen ethnic4= ethnic2
label var ethnic4 "ethnicity short 3 categories- without mixed"
recode ethnic4 (3/4=.) 
label define ethnic4lb 0 "native" 1 "Turkey(D)/Maghreb(F)" 2 "other MB" , replace
label value ethnic4 ethnic4lb
tab ethnic4

recode ethn1FR (4=2)(5=3)(6=4)(7/8=.) (99=.), gen(ethnic5)
lab var ethnic5 "ethnicity 4 cat. - by continents withouth mixed"
lab define ethnic5lb 0 "native" 1 "Europe" 2 "Africa" 3 "Asia, including Ex-Soviet & Turkey (D) and Middle East (F)" 4 "Rest of World"
lab value ethnic5 ethnic5lb

*generation
gen generat1= generat1FR
label var generat1 "immigration generation - large"
label define generat1lb ///
0 "no immigration" ///
1 "kid foreign: immigrated >=5 yrs age or no information about age of immigration" ///
2 "kid foreign: immigrated < 5 yrs age" ///
3 "kid native: parents foreign, less than two gp native" ///
4 "kid native: parents foreign, two or more gp native" ///
5 "kid native: one parent native, less than two gp native" ///
6 "kid native: one parent native, two gp native" ///
7 "kid native: two parents native, less than two gp native" ///
8 "kid native: two parents native, two gp native" ///
99 "missing", replace
label value generat1 generat1lb

gen generat2= generat2FR
label var generat2 "immigration generation - short mixed separate"
label define generat2lb ///
0 "no immigration" ///
1 "1. generation, kid immigrated >=5 yrs age or no information about age of immigration" ///
2 "1. generation, kid immigrated < 5 yrs age" ///
3 "2. generation" ///
4 "3. generation" ///
5 "1 parent foreign + 2 gp foreign, 1 parent native + 2 gp native" ///
99 "missing", replace
label value generat2 generat2lb

gen generat3= generat3FR
label var generat3 "immigration generation - short mixed 2. generation"
label define generat3lb ///
0 "no immigration" ///
1 "1. generation, kid immigrated >=5 yrs age or no information about age of immigration" ///
2 "1. generation, kid immigrated < 5 yrs age" ///
3 "2. generation" ///
4 "3. generation" ///
99 "missing", replace
label value generat3 generat3lb

******** ******** ******** ******** ******** ******** 
*** national identiy
gen natident1 = Q13
recode natident1 (.= 99)

lab var natident1 "identity as native or group of origin - large"
label define natident1lb 1"completely FR/GE" 2"more FR/GE" 3"devided" 4"more group of origin" 5"completely group of origin" 99 "missing", replace
label val natident1 natident1lb

recode natident1 (1/2=1) (4/5=3) (3=2), gen (natident2)
lab var natident2 "identity as native or group of origin - short"
lab  define natident2lb 1"host country" 2"divided" 3"country of origin" 99 "missing", replace
label val natident2 natident2lb

fre natident1 natident2

*** citizenship as adult	
gen citizen = Q7
replace citizen=. if ethn1FR==0 
label variable citizen "decision for citizenship"
label define citizenlb 1"only host country" 2 "only country of origin" 3 "both citizenships"
label value citizen citizenlb

******** ******** ******** ******** ******** ********
** religion
gen relig1= Q46
recode relig1 (1=4) (2=3) (3=2) (4=1) (.=99)

label var relig1 "importance of religion"
label define relig1lb 1 "not important at all"  2 "fairily important" 3 "important" 4  "very important" 99 "missing", replace 
label value relig1 relig1lb

recode relig1 (1/2=0) (3/4=1), gen(relig2)
label var relig2 "importance of religion- dummy"
label define relig2lb 0"not important" 1 "important" 99 "missing", replace 
label value relig2 relig2lb

fre relig1 relig2

******************************** FAMILY ENVIRONMENT ********************************
******** education
recode Q11S1(5=0) (6=0) (.=0) , gen (educ_m)
recode Q11S2 (5=0) (6=0) (.=0) , gen (educ_p) 
label var educ_m "education mother"
label var educ_p "education father"

gen educ1 = -1
replace educ1 = educ_p if educ_p >= educ_m
replace educ1 = educ_m if educ_p < educ_m
lab var educ1 "highest education of mother/father"
lab define educ1lb  0"don't know/NA/other" 1"no degree" 2"degree below bac/Abi" 3"Bac/Abi" 4"above Bac/Abi" ,replace
label value educ1 educ1lb
tab educ1, m

recode educ1 (4=1) (0/3=0), gen (educ2)
lab var educ2 "highest education of mother/father dichot."
lab define educ2lb  0"else/don't know/NA" 1"Above Bac/Abi" 99 "missing", replace
label value educ2 educ2lb

tab educ1, m
tab educ2, m

******** unemployement
***** dole_m/dole_p:  for mother/father separately
***** dole1/dole2 : one/both parents, plus combinations of don't know/no answer
gen dole_m=-1
replace dole_m = 1 if Q14S1 == 3 | Q15S1 == 1
replace dole_m=0 if dole_m==-1 & (Q14S1 != 10 & Q14S1 != 3) & Q15S1== 2 
replace dole_m =2 if dole_m==-1 & (Q14S1 == 10 | Q14S1==99) & Q15S1 != 1 
replace dole_m=2 if dole_m==-1 &(Q14S1 != 10 & Q14S1 != 3) & (Q15S1== 3 | Q15S1==99 | Q15S1==.)
replace dole_m=99 if dole_m==-1 & Q14S1 ==99 & (Q15S1==99 | Q15S1==.) 
recode dole_m (99=2)
lab var dole_m "mother unemployed (now or last year)"
lab define dole_mlb 0"no" 1"yes" 2"don't know/no answ./sysmis", replace
label value dole_m dole_mlb
tab dole_m, m

gen dole_p=-1
replace dole_p= 1 if Q14S2 == 3 | Q15S2 == 1 
replace dole_p=0 if dole_p==-1 & (Q14S2 != 10 & Q14S2 != 3) & Q15S2== 2 
replace dole_p = 2 if dole_p==-1 & (Q14S2 == 10 | Q14S2==99) & Q15S2 != 1 
replace dole_p=2 if dole_p==-1 & (Q14S2 != 10 | Q14S2 != 3) & (Q15S2== 3 | Q15S2==99 | Q15S2==.)
replace dole_p=99 if dole_p==-1 & Q14S2 == 99 & (Q15S2==99 | Q15S2==.) 
recode dole_p (99=2)
lab var dole_p "father unemployed (now or last year)"
lab define dole_plb 0"no" 1"yes" 2"don't know/no answ./sysmis", replace
label value dole_p dole_plb
tab dole_p, m

gen dole1=-1

replace dole1=0 if dole_p == 0 & dole_m == 0
replace dole1=0 if (dole_p ==2 & dole_m == 0 )| (dole_p == 0 & dole_m == 2)
replace dole1=1 if (dole_p == 1 & dole_m == 0) | (dole_p == 0 & dole_m == 1)
replace dole1=2 if (dole_p == 1 & dole_m == 2) | (dole_p == 2 & dole_m == 1)
replace dole1=2 if dole_p == 2 & dole_m == 2
replace dole1=3 if dole_p == 1 & dole_m == 1
lab var dole1 "unemployed parents"
lab define dole1lb 0"moth. and fath. employed or one employed and one unclear" 1"moth. or fath. unemployed (other employed)" 2"moth. or fath. unemployed (other unclear) or both unclear" 3"both unemployed" , replace
label value dole1 dole1lb

gen dole2 = 0
replace dole2=1 if dole_m == 1 | dole_p == 1
replace dole2=2 if dole_m == 2 & dole_p== 2
lab var dole2 "mother or father unemployed"
lab define dole2lb 0"no" 1"yes" 2"unclear"
lab val dole2 dole2lb

fre dole_m dole_p dole1 dole2

******** status - differs from D
tab pcsr, m

fre pcsr R3PCSM R3PCSP

tab R3PCSM R3PCSP, m
tab pcsr R3PCSM, m
tab pcsr R3PCSP, m

/*
gen pcs2r = pcsr
replace pcs2r=1 if pcsr==. & R3PCSM==1
replace pcs2r=1 if pcsr==. & R3PCSP==1

replace pcs2r=3 if pcsr==. & R3PCSM==2  
replace pcs2r=3 if pcsr==. & R3PCSP==2

fre pcs2r
tab pcsr pcs2r, m

recode pcs2r (3=1) (1=3), gen(status)
recode status (.=99)
*/

fre pcsm pcsp
fre R3PCSM R3PCSP

/*
* PCSM et PCSP => 9 modalit�s :
1 "Agriculteurs exploitants"
2 "Artisans, commer�ants et chefs d'entreprise"
3 "Cadres et professions intellectuelles sup�rieures"
4 "Professions Interm�diaires"
5 "Employ�s"
6 "Ouvriers"
7 "Sans activit� professionnelle"
8 "Non codifiable (pas suffisamment pr�cis)"=> correspond � Q17S1I9 et Q17S2I9
99 "NR".=> correspond � Q17S1I7 et Q17S2I7 +  Q17S1I10 et Q17S2I10
 
2/ R3PCSM (M pour m�re) et R3PCSP (P pour p�re) correspondent � des recodages des variables PCSM et PCSP
R3PCSM = 1 "Profession favoris�e"  pour PCSM=1, 3, 4
R3PCSM = 2 "Profession modeste" pour PCSM=2, 5, 6, 7
R3PCSM = 3 "Non codifiable" pour PCSM=8
R3PCSM = 99 "Non r�ponse" pour PCSM=99
*/

gen pcsm1=pcsm
recode pcsm1 (1=1) (3=1) (4=1) (2=2) (5=2) (6=2) (7=2) (8=.) (99=.)

gen pcsp1=pcsp
recode pcsp1 (1=1) (3=1) (4=1) (2=2) (5=2) (6=2) (7=2) (8=.) (99=.)
fre pcsm1 pcsp1

gen PCShigh=.
replace PCShigh=1 if pcsm1 ==1 | pcsp1==1
replace PCShigh=2 if pcsm1 ==2 & pcsp1==2
replace PCShigh=2 if (pcsm1 ==2 & pcsp1==.) | (pcsm1 ==. & pcsp1==2)
fre PCShigh
spearman PCShigh dole2
tab PCShigh dole2, column row nokey chi2 lrchi2 V

graph bar (median) PCShigh, over(dole2)
graph bar (median) PCShigh, over(ethnic4)

gen status=PCShigh
label var status "social status family"

label define statuslb 2 "modest/intermediate" 1 "higher" , replace
label value status statuslb
fre status

******** ******** ******** ******** ******** ******** 
*family setting - REVIEW!!!!
summarize Q10I1 - Q10I10
summarize Q10nb5 Q10nb6 nbparents

tab nbparents, m

gen famsetd = 1
replace famsetd=0 if nbparents>=2 

recode famsetd (.=99) 
lab var famsetd "family setting - dichotom"
lab define famsetdlb 0 "complete" 1 "not complete or missing", replace 
lab value famsetd famsetdlb
fre famsetd

*Attachment to mother - differs from D

*REVIEW NUR EIN ITEM ZUR MESSUNG DER BEZIEHUNG ZUR MUTTER (ANDERS IN D)
/*
summarize Q19S1 R2Q19S1

recode Q19S1 (4=1) (3=2) (2=3) (1=4), gen (sattmtr)

label var sattmtr "positive attachement to mother"
lab define attmtrlb 1"yes, fully true" 2 "yes, rather true" 3 "no, rather untrue" 4 "no, not true at all", replace
label value sattmtr attmtrlb

*/

*parental monitoring - differs from D
recode Q21S1 (1=4) (2=3) (3=2) (4=1), gen (parmon2)
recode Q21S2 (1=4) (2=3) (3=2) (4=1), gen (parmon1)

lab var parmon1 "my parents know with whom I spend my free time"
lab var parmon2 "my parents know what I do during my free time "
lab define parmonlb 1"never" 2 "sometimes" 3"often" 4"almost always"
label value parmon1 parmon2 parmonlb

*mean scale dependend variable instead of factor variable for joint dataset
capture drop sparmon
egen sparmon=rowmean(parmon1 parmon2)

lab var sparmon "mean parental monitoring (higher=closer monitoring)"

******************************** SOCIAL ENVIRONMENT ********************************
*attitudes to school  - differs from D
recode Q31S1 (1=4) (2=3) (3=2) (4=1), gen (attsch1)
recode Q31S2 (1=4) (2=3) (3=2) (4=1), gen (attsch2)
recode Q31S3 (1=4) (2=3) (3=2) (4=1), gen (attsch3)

lab var  attsch1 "I like my school a lot " 
lab var  attsch2 "I am interested in what I am learning at school " 
lab var  attsch3 "I apply myself in school " 

lab define attschlb 1"yes, fully true" 2 "yes, rather true" 3 "no, rather untrue" 4 "no, not true at all"
label value attsch1-attsch3 attschlb

******** ******** ******** ******** ******** ******** 
*friends with migration background 
tab Q51, m

recode Q51 (1=5) (2=4) (4=2) (5=1), gen (mbfriendc)
lab var mbfriendc "friends with migration background"
lab define mbfriendclb 1 "none" 2 "less than half" 3 "half" 4 "more than half" 5 "all", replace
label value mbfriendc mbfriendclb

recode mbfriendc (5=0)(4=1)(3=1)(2=1), gen(mbfriend)
recode mbfriend (.=99)
lab var mbfriend "friends without migration background - dummy"
lab define mbfriendlb 0"no" 1"yes" 99 "missing", replace
label value mbfriend mbfriendlb

fre mbfriendc mbfriend

*free time activities - MISSING IN FR!!
* night out with friends
gen nights1 = Q53-1
gen nights2 = Q53-1

recode nights1 (.=99)
lab var nights1 "Nights out with friends (FR: after 18 h/DE: afternoon or evening)"
lab define  nights1lb 0"none" 1"once"  2"twice" 3"3-4 times" 4"5+ times" 99 "missing", replace
label value nights1 nights1lb

recode nights2 (.=99)
lab var nights2 "Nights out with friends (F: how many/G:how long?)"
lab define nights2lb  0"none" 1"FR: 1 DE: 20h" 2"FR: 2 DE: 21h" 3"FR: 3-4 DE: 22h"  4"FR: 5+ DE: after 22h"  99 "missing" , replace
label value nights2 nights2lb

* time back home
gen street = Q28S3-1
recode street (.=99) 
lab var street "being out on the street"
lab define streetlb 0"never" 1"rarely" 2"often" 3"very often" 99 "missing" 
label value street streetlb

*** alcohol
tab Q58autS13corv, m
recode Q58autS13corv (2/5=2) (6/max =3), gen (drunk)
recode drunk (.=99)
lab define drunklb 0"never" 1"once" 2"2-5 times" 3"6+ times" 99 "missing" 
lab var drunk "ever been drunk (lifetime)"
lab val drunk drunklb

fre nights1 nights2
fre drunk street

******************************** NEIGHBOURHOOD ********************************
**REVIEW AS 14/09/18: nhbd2 NOT REVERSED

*recode Q29S3 (4=1) (3=2) (2=3) (1=4) (else=copy) into Q29S3f.
*missing values Q29S3f (99).
gen nbhd1 = Q29S1
gen nbhd2 = Q29S3
gen nbhd3 = Q29S4
gen nbhd4 = Q30S1
gen nbhd5 = Q30S2
gen nbhd6 = Q30S3
corr nbhd1 nbhd2 nbhd3 nbhd4 nbhd5 nbhd6 

label var nbhd1 "feels well in neighbourhood"  
label var nbhd2 "good nbhd for children to grow up" 
label var nbhd3 "youths become delinQuent" 
label var nbhd4 "incivil: litter on street" 
label var nbhd5 "incivil: drugs" 
label var nbhd6 "incivil: violence" 

foreach v of var nbhd1 nbhd2 nbhd3 nbhd4 nbhd5 nbhd6 {
	recode `v' (.=99)
}

lab define nbhd13lb 1"not true at all" 2"not true" 3"true" 4"completely true" 99 "missing"
lab define nbhd46lb 1"never" 2"rarely" 3"often" 4"very often" 99 "missing"

label value nbhd1-nbhd3 nbhd13lb
label value nbhd4-nbhd6 nbhd46lb

foreach v of var nbhd* {
	tab `v', m
}

******************************** DELINQUENCY AND VICTIMISATION ********************************
*check scales
*attitudes favorable to delinquency - differs from D

recode Q41S1 (1=4) (2=3) (3=2) (4=1), gen (attviol1)
recode Q41S2 (1=4) (2=3) (3=2) (4=1), gen (attviol2)
recode Q41S3 (1=4) (2=3) (3=2) (4=1), gen (attviol4)
recode Q41S4 (1=4) (2=3) (3=2) (4=1), gen (attviol5)

lab var attviol1 "it is normal to beat somebody if one has been provoked"
lab var attviol2 "every dispute can be settled through talks"
lab var attviol4 "one has to respect the law, even if the own interests are overlooked"
lab var attviol5 "one can do something forbidden if he/she is not caught"

lab define attviollb 1"yes, fully true" 2 "yes, rather true" 3 "no, rather untrue" 4 "no, not true at all"

label value attviol1 attviol2 attviol4 attviol5  attviollb

******** ******** ******** ******** ******** ********  
** victimization joint DE FR dataset
gen vic1 = Q57vicS1corv          
gen vic2 = Q57vicS2corv          
gen vic3 = Q57vicS3corv          
gen vic4 = Q57vicS4corv         
 
lab var vic1 "theft" 
lab var vic2 "blackmail" 
lab var vic3 "assault" 
lab var vic4 "cyberbullying" 

egen vicmiss = anycount(vic1 vic2 vic3 vic4), values (99)

forvalues i=1/4 {
	replace vic`i'= 0 if vic`i'==99 & vicmiss <4
	recode vic`i' (99=.)
}

fre vic1 vic2 vic3 vic4

egen vic_sum= rowtotal(vic1 vic2 vic3 vic4), missing 
label var vic_sum "victimization - incid."

recode vic_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(vic_k)
lab var vic_k "victimization - cat."
label define vic_klb 0"0" 1"1" 2"2" 3"3-5" 4"6-10" 5">10"
lab value vic_k vic_klb

recode vic_k (1/2=1) (3=2) (4/5=3), gen(vic_k2)
lab var vic_k2 "victimization - cat. short"
label define vic_k2lb 0 "0" 1 "1-2" 2 "3-5" 3 ">5", replace


******** ******** ******** ******** ******** ******** 
****SRD (2014/03/29)
fre Q58autS1corv - Q58autS9corv

gen srd1 	=	Q58autS1corv
gen srd2	=	Q58autS4corv
gen srd3	=	Q58autS5corv
gen srd4	=	Q58autS6corv
gen srd5	=	Q58autS7corv
gen srd6	=	Q58autS8corv
gen srd7	=	Q58autS9corv

lab var srd1 "vandalism" 
lab var srd2 "vehicle theft" 
lab var srd3 "shoplifting" 
lab var srd4 "break in" 
lab var srd5 "use drugs" 
lab var srd6 "sell drugs" 
lab var srd7 "assault"

egen srdmiss = anycount(srd1 srd2 srd3 srd4 srd5 srd6 srd7), values (99)
fre srdmiss

forvalues i=1/7 {
	replace srd`i'= 0 if srd`i'==99 & srdmiss <7
	recode srd`i' (99=.)
}

egen srd_sum= rowtotal(srd1 srd2 srd3 srd4 srd5 srd6 srd7), missing 
label var srd_sum "numb. self reported delinquency - incid."

recode srd_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(srd_k)
lab var srd_k "self reported delinquency - cat."
label define srd_klb 0"0" 1"1" 2"2" 3"3-5" 4"6-10" 5">10"
lab value srd_k srd_klb

recode srd_k (1/2=1) (3=2) (4/5=3), gen(srd_k2)
lab var srd_k2 "self reported delinquency - cat. short"
label define srd_k2lb 0 "0" 1 "1-2" 2 "3-5" 3 ">5", replace
label value srd_k2 srd_k2lb 


******** ******** ******** ******** ******** ******** 
* peer delinquency - differs from D
gen peerdel2 = Q55S1-1
recode peerdel2 (9=.)
gen peerdel5 = Q55S2-1
recode peerdel5 (9=.)
gen peerdel6 =Q55S4-1
recode peerdel6 (9=.)
gen peerdel7 = Q55S5-1
recode peerdel7 (9=.)
gen peerdel10 = Q55S3-1
recode peerdel10 (9=.)

fre Q55S1
fre peerdel2

lab var peerdel2 "volontarely damaged something"
lab var peerdel5 "violently stolen something from somebody"
lab var peerdel6 "injured somebody seriousely"
lab var peerdel7 "used drugs"
lab var peerdel10 "throwed objects on police cars/buses"

egen peerdel_sum=rowtotal(peerdel2 peerdel5 peerdel6 peerdel7), missing

label var peerdel_sum "delinquency of peers - versatility"

recode peerdel_sum (0=0) (1=1)(2/max=2), gen(peerdel_k)

lab var peerdel_k "delinquency of peers - cat."
label define  peerdellb  0 "none" 1 "one" 2 "several" 
label value peerdel_k peerdellb 

foreach var in peerdel2 peerdel5 peerdel6 peerdel7 peerdel10 {
	recode `var' (0=1)(1=2)(2=3)
}

*** polychoric scale instead of mean
*egen speerdel=rowmean(peerdel2 peerdel5 peerdel6 peerdel7)


******************************** POLICE CONTACT ********************************
******** ******** ******** ******** ******** ********
***pcont (police contact)
***Bearbeitete Variablen.
describe  Q66S1cori Q66S2cori Q66S3cori Q66S4cori Q66S5cori Q66S6cori Q66S7cori Q66S8cori
describe  Q66S1corv Q66S2corv Q66S3corv Q66S4corv Q66S5corv Q66S6corv Q66S7corv Q66S8corv 

gen pcont1  =   Q66S1corv2
gen pcont2  =   Q66S2corv2
gen pcont3  =   Q66S3corv2
gen pcont4  =   Q66S4corv2
gen pcont5  =   Q66S6corv2
gen pcont6  =   Q66S7corv2
gen pcont7  =   Q66S5corv2
gen pcont8  =   Q66S8corv2

lab var pcont1 "As a witness or victim of a traffic offence/ accident" 
lab var pcont2 "As a witness of a criminal offence" 
lab var pcont3 "As a victim of a criminal offence"
lab var pcont4 "As a suspect of a criminal offence (e.g. shoplifting, brawl/fighting)" 
lab var pcont5 "As a traffic participant (e. g. on a bike ride)" 
lab var pcont6 "I was approached or checked (stopped and searched) on the street/ in a park/ on a public square"
lab var pcont7 "I talked to a police officer because I wanted to know something/ to get help"
lab var pcont8 "For other reasons"

fre pcont1 pcont2 pcont3 pcont4 pcont5 pcont6 pcont7 pcont8

foreach v of var pcont1 pcont2 pcont3 pcont4 pcont5 pcont6 pcont7 pcont8 {
	recode `v' (20/100 = 20) (101/max=-1), gen(`v'r)
	recode `v'r (-1 99=.)
	tab `v'r
}

foreach v of var pcont1 pcont2 pcont3 pcont4 pcont5 pcont6 pcont7 pcont8 {
	recode `v' (1/100=1) (101/max=-1), gen (`v'd)
	recode `v'd (-1 99=.)
	tab `v'd
}

egen pcont_sum= rowtotal(pcont1r pcont2r pcont3r pcont4r pcont5r pcont6r pcont7r pcont8r), missing
label var pcont_sum "number of police contacts last year - incid."

recode pcont_sum  (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(pcont_k)
recode pcont_sum  (0=0) (1/2=1) (3/5=2) (6/max=3), gen(pcont_k2)
recode pcont_sum  (0=0) (1/max=1), gen(pcont_d)

label var pcont_k "number of police contacts last year - cat."
label define pcont_klb 0"0" 1"1" 2"2" 3"3-5" 4"6-10" 5">10"
label value pcont_k pcont_klb

label var pcont_k2 "number of police contacts last year - cat. short"
label define pcont_k2lb 0"0" 1"1-2" 2"3-5" 3">5"
label value pcont_k2 pcont_k2lb

label var pcont_d "police contact last year - dummy"
label value pcont_d dummylb

******** ******** ******** ******** ******** ******** 
*** types of police contact
*** police contact victim/witness/self-initiated

egen pconta_sum= rowtotal(pcont1r pcont2r pcont3r pcont7r), missing
label var pconta_sum "numb. pol.contacts last yr, witness/victim/self-init. (1/2/3/7) - incid."

recode pconta_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(pconta_k)
label var pconta_k "numb. pol.contacts last yr, witness/victim/self-init. (1/2/3/7) - cat."
lab value pconta_k pcont_klb

recode pconta_k (0=0)(1/2=1) (3=2) (4/max=3), gen (pconta_k2)
label var pconta_k2 "numb. pol.contacts last yr, witness/victim/self-init. (1/2/3/7) - cat. short"
label value pconta_k2 pcont_k2lb

recode pconta_k2 (1/3=1), gen(pcontad)
fre pconta_sum pconta_k pconta_k2 

*police contact as crime/suspect 
recode pcont4r  (0=0) (1/2=1) (3/5=2) (6/max=3), gen(pcont4_k)
label var pcont4_k "number of police contacts as crime suspect last year (4) - cat."
lab val pcont4_k pcont_k2lb
fre pcont4_k

*** police contact control/suspicion
egen pcontb_sum= rowtotal(pcont4r pcont5r pcont6r), missing
label var pcontb_sum "numb. pol.contacts last yr, suspicion/traffic control/stopped on street (4/5/6) - incid."

recode pcontb_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(pcontb_k)
recode pcontb_k (2.5=2)
lab var pcontb_k "numb. pol.contacts last yr, suspicion/traffic control/stopped on street (4/5/6) - cat."
lab value pcontb_k pcont_klb

recode pcontb_k (0=0)(1/2=1) (3=2) (4/max=3), gen (pcontb_k2)
lab var pcontb_k2 "numb. pol.contacts last yr, suspicion/traffic control/stopped on street (4/5/6) - cat. short"
label value pcontb_k2 pcont_k2lb

recode pcontb_k2 (1/3=1), gen(pcontbd)

fre pcontb_sum pcontb_k pcontb_k2 

*** police contact control only
egen pcontc_sum= rowtotal(pcont5r pcont6r), missing
label var pcontc_sum "numb. pol.contacts last yr, traffic control/stopped on street (5/6)- incid."

recode pcontc_sum   (0=0) (1=1) (2=2) (3/5=3) (6/10=4) (11/max=5), gen(pcontc_k)
recode pcontc_k (2.5=2)
lab var pcontc_k "numb. pol.contacts last yr, traffic control/stopped on street (5/6) - cat."
lab value pcontc_k pcont_klb

recode pcontc_k (0=0)(1/2=1) (3=2) (4/max=3), gen (pcontc_k2)
lab var pcontc_k2 "numb. pol.contacts last yr, traffic control/stopped on street (5/6) - cat. short"
label value pcontc_k2 pcont_k2lb

recode pcontc_k2 (1/3=1), gen(pcontcd)

******** ******** ******** ******** ******** ******** 
***last contact
tab Q66last_filter, m
tab Q67Q74_filter, m
tab Q66Q74_filter, m

gen lastcont1= Q66last_filter
lab var lastcont1 "filter for most recent contact with police"
label define lastcont1lb 99 "missing" 0 "no police contact" 1 "one type of police contact" 2 "several types police contacts", replace 
label value lastcont1 lastcont1lb
fre lastcont1

gen lastcont2= Q67Q74_filter
lab var lastcont2 "filter for validity of questions about last contact"
label define lastcont2lb  99"missing" 1"valid", replace
label value lastcont2 lastcont2lb
fre lastcont2

recode Q66Q74_filter (0=0) (3=1) (2=2) (1=3), gen(lastcont3)
lab var lastcont3 "FINAL FILTER for last contact"
label define lastcont3lb 99 "police contact missing + no valid information about contact" ///
0 "no police contact" ///
1 "filter valid: one type of police contacts" ///
2 "filter valid: several types of police contacts" ///
3 "filter not valid: one or more police contacts", replace 
label value lastcont3 lastcont3lb
fre  lastcont3

*review
fre Q66Ssumc Q66Spolc Q66Sselfc Q66S8corv2r
tab Q66Ssumc lastcont1, m
tab Q66Ssumc lastcont3, m


******************************** EXPERIENCES WITH THE POLICE ********************************
*** pleg (police legitimacy)
gen pleg1 =	Q61S1
gen pleg2 =	Q61S5
gen pleg3 =	Q59S9
gen pleg4 =	Q59S2
gen pleg5 =	Q59S6
gen pleg6 =	Q59S3
gen pleg7 =	Q61S4
gen pleg8 =	Q59S7

lab var pleg1 "The police protect adolescents"
lab var pleg2 "The police disrespect adolescents"
lab var pleg3 "Overall the police can be trusted"
lab var pleg4 "One should in any case follow the instructions of the police"
lab var pleg5 "Even if having a serious problem, I would never contact the police"
lab var pleg6 "If adolescents protest violently and with riots against the police, I would join them"
lab var pleg7 "The police treat foreigners worse than native people"
lab var pleg8 "I could imagine becoming a police officer myself once"

lab define pleglb 1"don't agree at all" 2"don't agree" 3"agree" 4"completely agree"
lab value pleg1-pleg8 pleglb
fre  pleg1 pleg2 pleg3 pleg4 pleg5 pleg6 pleg7 pleg8

******** ******** ******** ******** ******** ******** 
*** vicexp (vicarious experiences)

** Q63 Q64 into vicepx2?
gen vicexp1 = Q62
gen vicexp2 = Q64
gen vicexp3 = Q63

lab var vicexp1 "I witnessed it myself"  
lab var vicexp2 "Somebody reported me to have been treated with disrespect"
lab var vicexp3 "A member of my family reported to have been treated with disrespect"
lab define vicexplb 1"no, never" 2 "yes, once" 3 "yes, many times", replace
label value vicexp1 vicexp2 vicexp3 vicexplb
fre vicexp1 vicexp2 vicexp3

*mean scale dependend variable instead of factor variable
capture drop svicexp
egen svicexp=rowmean(vicexp1 vicexp2)
lab var svicexp "mean vicarious experiences (higher=worse)"

******** ******** ******** ******** ******** ******** 
*** (police behavior)
***Bearbeitete Variablen.
describe  Q71S1cori Q71S3cori Q71S4cori Q71S5cori 
drop pbeh1-pbeh4 spbehr

gen pbeh1	=	Q71S1cori
gen pbeh2	=	Q71S3cori
gen pbeh3	=	Q71S4cori
gen pbeh4	=	Q71S5cori

lab var pbeh1 "The police have explained honestly the reasons for their action"
lab var pbeh2 "The police treated me/us fairly and with respect"
lab var pbeh3 "The police tried to provoke or offend"
lab var pbeh4 "The police became violent"

*label define pbehlb 1"yes, fully true" 2 "yes, rather true" 3 "no, rather untrue" 4 "no, not true at all"
*label value pbeh1-pbeh4 pbehlb

fre pbeh1 pbeh2 pbeh3 pbeh4

******** ******** ******** ******** ******** ******** 
***ybeh (youth behavior)
***fre Q72I1cori Q72I2cori Q72I3cori Q72I4cori Q72I5cori Q72I6cori Q72I7cori Q73S1cori.
recode Q73S1corir (2=0) 

gen ybeh1	=	Q72I1corir
gen ybeh2   =	Q73S1corir
gen ybeh3	=	Q72I2corir
gen ybeh4	=	Q72I3corir
gen ybeh5	=	Q72I5corir
gen ybeh6	=	Q72I6corir

lab var ybeh1 "you behaved normally and orderly"
lab var ybeh2 "you had drunk alcohol"
lab var ybeh3  "you resisted the police"
lab var ybeh4 "you provoked the police"
lab var ybeh5 "you ran away"
lab var ybeh6 "for other reasons"

label define ybehlb 0 "no" 1 "yes"
lab value ybeh1-ybeh6 ybehlb
fre ybeh1 ybeh2 ybeh3 ybeh4 ybeh5 ybeh6

******** ******** ******** ******** ******** ******** 
*** intermmt (moment of interaction)
fre Q67
gen intermmt = Q67
label var intermmt "moment of interaction"
label define intermmtlb 1 "morning" 2 "afternoon" 3"evening" 4 "night"
label value intermmt intermmtlb

******** ******** ******** ******** ******** ******** 
*** interyth presence of other people
fre Q68S1corir Q68S2corir
gen interyth = .

replace interyth=1 if Q68S1corir==2 & Q68S2corir==2
replace interyth=3 if Q68S2corir==1
replace interyth=2 if Q68S1corir==1


label var interyth "presence of other people"
label define interythlb 1 "alone" 2 "with other youth" 3"with other adult people"
label value interyth interythlb

******** ******** ******** ******** ******** ******** 
*** interplc place of interaction
fre Q69corir 
gen interplc = Q69corir
replace interplc=. if Q69corir==3

label var interplc "place of interaction"
label define interplclb 1 "own neighborhood" 2 "city centre" 
label value interplc interplclb

******** ******** ******** ******** ******** ******** 
*** pact (action police)
fre Q70I1corir-Q70I7corir

gen pact1 = Q70I1corir
gen pact2 = Q70I3corir
gen pact3 = Q70I2corir
gen pact4 = Q70I4corir
gen pact5 = Q70I5corir
gen pact6 = Q70I6corir
gen pact7 = Q70I7corir

lab var pact1 "The police have checked my cloths/bags"
lab var pact2 "The police have checked my identity"
lab var pact3  "The police deecred an order to move"
lab var pact4 "The police took me to the police station"
lab var pact5 "I had to stay at the police station/asylum overnight"
lab var pact6 "The police spoke with my parents"
lab var pact7 "The police initiated a criminal proceeding"

label define pactlb 0 "no" 1 "yes"
lab value pact1-pact7 pactlb


*save
save "../../STATAfiles/S11FR_version4.dta", replace
compress






